package cz.incad.psh.pshassign.server.search;

import cz.incad.psh.pshassign.server.Options;
import cz.incad.psh.pshassign.server.search.Search;
import java.io.InputStream;
import java.io.StringWriter;
import org.apache.commons.io.IOUtils;

/**
 *
 * @author Alberto Hernandez
 */
public class VectorsSearch implements Search {

    public VectorsSearch() {
    }

    @Override
    public String doSearch(String id) {
        try {
            String urlStr = Options.getOption("invenio", "solr") + "/tvrh?wt=json&q=id:" + id;
            
            java.net.URL url = new java.net.URL(urlStr);
            
            InputStream is = url.openStream();
  
            StringWriter writer = new StringWriter();
            IOUtils.copy(is, writer, "UTF-8");
            return writer.toString();
            
        } catch (Exception e) {
            System.out.println("error :\n" + e);
            e.printStackTrace();
            return "error " + e;
        }
    }
    
}
